﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;

using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace wrzy
{
    class fzj
    {
        Byte[] bDISts = new Byte[16];
        Byte[] bDOSts = new Byte[16];
        Button[] DOSts = new Button[16];
        Button[] DISts = new Button[16];
        IntPtr hDevice;
        Int32 DeviceLgcID;
        int InPort, OutPort;//一个是输入的端口，一个是输出的端口
        public fzj()//利用构造函数进行设备的初始化
        {
            for (int index = 0; index < 16; index++)
            {
                bDOSts[index] = 0;
                bDISts[index] = 0;

            }
            hDevice = PCI2312.PCI2312_CreateDevice(DeviceLgcID);
            if (hDevice == (IntPtr)(-1))
            {
                MessageBox.Show("创建设备失败！");
                return;
            }
        }
        /// <summary>
        /// 调用这个方法的作用是返回封闭机当前的状态
        /// </summary>
        /// <returns>
        /// 如果封闭机已经准备好了，返回true，否则返回false
        /// </returns>
        public Boolean fzjStatus()
        {
            if (hDevice != (IntPtr)(-1))
            {
                MessageBox.Show("PCI2312_GetDeviceDI Error...");
                return false;
            }
            if (bDISts[this.OutPort] == 1)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 当用户不再使用封闭机时，调用这个方法来释放设备对象
        /// </summary>
        public void fzjClose()  
        {
            if (hDevice != (IntPtr)(-1))
            {
                PCI2312.PCI2312_ReleaseDevice(hDevice);      // 释放设备对象	
            }
        }
        /// <summary>
        /// 封装一次
        /// </summary>
        public void fzjStart()
        {
            bDOSts[2] = 1;
            bDISts[2] = 1;

            Thread.Sleep(2000);
            bDOSts[2] = 0;
            bDISts[2] = 0;
        }
    }
}
